/*----------------------------------------------------------------------------\
|                                组织结构JS
|-----------------------------------------------------------------------------
|                   Copyright (c) 2003 Gnct
|               作者:luoshiqiang(email:Imlsq@hotmail.com)
\----------------------------------------------------------------------------*/

/**
* OrgVOJs class
* @return
*/
function OrgVOJs()
{
    this.orgBCFL="";//本层标志
    this.orgName="";
    this.orgSCFL="";//上层标志
    this.orgType="";
    this.orgCode="";
    this.corpCode="";
    this.flgPetitDusty="N"; //次要责任标识
    this.flgOrgType="";
    this.flgCheck="Y";
    this.flgShowCheck="N";
    this.restrict="";
    this.restrictCount="-1";//数量限制
    this.orgCollection =new Array();//集合
}

OrgVOJs.prototype.setRestrictCount=function (partment)
{
  if(partment=="")
    partment="-1";
  this.restrictCount=partment;
}

OrgVOJs.prototype.getRestrictCount=function()
{
  return this.restrictCount;
}


OrgVOJs.prototype.setRestrict=function (partment)
{
  this.restrict=partment;
}

OrgVOJs.prototype.getRestrict=function()
{
  return this.restrict;
}

OrgVOJs.prototype.setFlgCheck=function (partment)
{
  this.flgCheck=partment;
}

OrgVOJs.prototype.getFlgCheck=function()
{
  return this.flgCheck;
}

OrgVOJs.prototype.setFlgShowCheck=function (partment)
{
  this.flgShowCheck=partment;
}

OrgVOJs.prototype.getFlgShowCheck=function()
{
  return this.flgShowCheck;
}


OrgVOJs.prototype.setFlgOrgType=function (partment)
{
  this.flgOrgType=partment;
}

OrgVOJs.prototype.getFlgOrgType=function()
{
  return this.flgOrgType;
}

OrgVOJs.prototype.setFlgPetitDusty=function (partment)
{
  this.flgPetitDusty=partment;
}
OrgVOJs.prototype.getFlgPetitDusty=function()
{
  return this.flgPetitDusty;
}

OrgVOJs.prototype.setOrgBCFL=function (partment)
{
     this.orgBCFL=partment;
}

OrgVOJs.prototype.getOrgBCFL=function ()
{
    return this.orgBCFL;
}

OrgVOJs.prototype.setOrgName=function (partment)
{
    this.orgName=partment;
}

OrgVOJs.prototype.getOrgName=function ()
{
    return this.orgName;
}

OrgVOJs.prototype.setOrgSCFL=function (partment)
{
   this.orgSCFL=partment;
}

OrgVOJs.prototype.getOrgSCFL=function ()
{
   return this.orgSCFL;
}

OrgVOJs.prototype.setOrgType=function (partment)
{
   this.orgType=partment;
}

OrgVOJs.prototype.getOrgType=function ()
{
  return this.orgType;
}

OrgVOJs.prototype.setOrgCode=function (partment)
{
  this.orgCode=partment;
}

OrgVOJs.prototype.getOrgCode=function ()
{
  return this.orgCode;
}

OrgVOJs.prototype.setCorpCode=function (partment)
{
   this.corpCode=partment;
}

OrgVOJs.prototype.getCorpCode=function ()
{
  return this.corpCode;
}

OrgVOJs.prototype.addOrg2=function (orgObject)
{
    var objCount=this.orgCollection.length;

    var Iweary=new OrgVOJs();

    Iweary.setOrgBCFL(orgObject.getOrgBCFL());
    Iweary.setOrgName(orgObject.getOrgName());
    Iweary.setOrgSCFL(orgObject.getOrgSCFL());
    Iweary.setOrgType(orgObject.getOrgType());
    Iweary.setOrgCode(orgObject.getOrgCode());
    Iweary.setFlgCheck(orgObject.getFlgCheck());
    this.orgCollection[objCount]=Iweary;
}

/**
* 增加对象
*/
OrgVOJs.prototype.addOrg=function (orgBCFL,orgName,orgSCFL,orgType,orgCode,flgPetitDusty,corpCode,flgCheck)
{
    this.orgBCFL=orgBCFL;
    this.orgName=orgName;
    this.orgSCFL=orgSCFL;
    this.orgType=orgType;
    this.orgCode=orgCode;
    this.corpCode=corpCode;
    this.flgPetitDusty=flgPetitDusty;

    var objCount=this.orgCollection.length;
    var Iweary=new OrgVOJs();
    Iweary.setOrgBCFL(orgBCFL);
    Iweary.setOrgName(orgName);
    Iweary.setOrgSCFL(orgSCFL);
    Iweary.setOrgType(orgType);
    Iweary.setOrgCode(orgCode);
    Iweary.setCorpCode(corpCode)
    Iweary.setFlgCheck(flgCheck);
    Iweary.setFlgPetitDusty(flgPetitDusty);
    this.orgCollection[objCount]=Iweary;
}

/**
* 两个对象交换位置
*/
OrgVOJs.prototype.permutation=function(code1,code2)
{
   var index1=this.getOrgIndex(code1);
   var index2=this.getOrgIndex(code2);
   if(index1==-1 || index2==-1)
      return;
   var temWeizhi=this.fndbyIndex(index1);
   this.orgCollection[index1]=this.fndbyIndex(index2);
   this.orgCollection[index2]=temWeizhi;
   temWeizhi=null;
}
/**
* 查找某个对象所在的位置
*/
OrgVOJs.prototype.getOrgIndex=function(orgCode)
{
  var index=-1;
  var objCount=this.orgCollection.length;
   for(var i=0;i<objCount;i++)
   {
      var tmpobj=this.orgCollection[i];
      if(tmpobj!=null)
      {
         if(tmpobj.getOrgCode()==orgCode)
         {
            index=i;
            break;
         }
      }
   }
   return index;
}

OrgVOJs.prototype.clearObj=function ()
{
  try
  {
   var objCount=this.orgCollection.length;
   this.orgCollection.splice(0,objCount);
  }catch(ex)
  {
  }

}

OrgVOJs.prototype.delOrgByIndex=function (index)
{
  try{
    this.orgCollection.splice(index,1);
  }catch(e){
  }
}
/**
* 删除某个数组对象
*/
OrgVOJs.prototype.delOrg=function (orgCode)
{
   var objCount=this.orgCollection.length;

   for(var i=0;i<objCount;i++)
   {
      var tmpobj=this.orgCollection[i];
      if(tmpobj!=null)
      {
         if(tmpobj.getOrgCode()==orgCode)
         {
            this.orgCollection.splice(i,1);
            return;
         }
      }
      tmpobj=null;
   }
}

/**
* 查找某个数组对象
*/
OrgVOJs.prototype.fndbyOrgCode= function (orgCode)
{
  if(orgCode==null) return null;

  var objCount=this.orgCollection.length;
  var tmpobj=null;
   for(var i=0;i<objCount;i++)
   {
      tmpobj=this.orgCollection[i];
      if(tmpobj!=null)
      {
         if(tmpobj.getOrgCode()==orgCode)
         {
            return tmpobj;
         }
      }
      tmpobj=null;
   }
  return null;
}

/**
* 查找某个数组对象
*/
OrgVOJs.prototype.fndbyIndex= function (pindex)
{
  try
  {
     var tmpobj=this.orgCollection[pindex];
     return tmpobj
  }
  catch(ex)
  {
  }
  return null;
}


/**
*得到记录数
*/
OrgVOJs.prototype.getOrgCount=function ()
{
  return this.orgCollection.length;
}

// add by hansomee
//-------------------------------------------------------------------------

var currentlyObj=null;      //dialog 要用到的临时变量
function ev_selectOrg(currObj,fieldname,fieldcode,fieldtype,orgtype,isDiv)
{
    if (currObj == null)
       currentlyObj= new OrgVOJs();
    else
       currentlyObj = currObj;
    currentlyObj.setFlgOrgType(orgtype);
     showModalDialog("/PubUI/PUI_OrgSelect.jsp?workGroup=Y",window,'dialogHeight:420px;dialogWidth:330px;status=off');
     if (isDiv == 'Y')
         showOrgDIV(currentlyObj,fieldname,fieldcode,fieldtype);
     else
         showOrg(currentlyObj,fieldname,fieldcode,fieldtype);
     currentlyObj=null;
}

function showOrg(curObj,fieldname,fieldcode,fieldtype)
{
  var codes ="";
  var types ="";
  var names ="";

  if (curObj != null && curObj.getOrgCount()>0 )
  {

     var tmpOrg=curObj.fndbyIndex(0);
     names = tmpOrg.getOrgName();
     codes = tmpOrg.getOrgCode();
     types = tmpOrg.getOrgType();

	for(var i=1;i<curObj.getOrgCount();i++)
	{
		tmporg=curObj.fndbyIndex(i);
		if(tmporg!=null)
		{
		names += "、"+tmporg.getOrgName();
		codes += "、"+tmporg.getOrgCode();
		types += "、"+tmporg.getOrgType();

	  	}
         }
   }
  if (document.all(fieldname) != null)
   document.all(fieldname).value =names;
  if (document.all(fieldcode) != null)
   document.all(fieldcode).value = codes;
  if (document.all(fieldtype) != null)
   document.all(fieldtype).value = types;
}

function showOrgDIV(curObj,fieldname,fieldcode,fieldtype)
{
  var codes ="";
  var types ="";
  var names ="";

  if (curObj != null && curObj.getOrgCount()>0 )
  {

     var tmpOrg=curObj.fndbyIndex(0);
     names = tmpOrg.getOrgName();
     codes = tmpOrg.getOrgCode();
     types = tmpOrg.getOrgType();

	for(var i=1;i<curObj.getOrgCount();i++)
	{
		tmporg=curObj.fndbyIndex(i);
		if(tmporg!=null)
		{
		names += "、"+tmporg.getOrgName();
		codes += "、"+tmporg.getOrgCode();
		types += "、"+tmporg.getOrgType();

	  	}
         }
   }
  if (document.all(fieldname) != null)
   document.all(fieldname).innerHTML =names;
  if (document.all(fieldcode) != null)
   document.all(fieldcode).value = codes;
  if (document.all(fieldtype) != null)
   document.all(fieldtype).value = types;
}

